package com.example.netty.common;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

/**
 * @author zclever <304078606@qq.com>
 * @date 2021-03-02
 */
public class Message {

    private int type;
    private Object content;

    public Message(){
    }

    public Message(int type) {
        this.type = type;
    }

    public Message(int type, Object content) {
        this.type = type;
        this.content = content;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public Object getContent() {
        return content;
    }

    public void setContent(Object content) {
        this.content = content;
    }

    public String toJSON(){
        return JSON.toJSONString(this, SerializerFeature.DisableCircularReferenceDetect);
    }

    public Object toMsg() {
        return new TextWebSocketFrame(this.toJSON());
    }

}
